package com.myres.util;
import com.myres.db.ModelService;
import com.myres.model.Score;
import com.myres.model.Message;

public class ScoreTool {
	public static int parseScore(float payment){
		int score=0;
		if(payment<10){
			score+=payment/2;
		}else if(payment<50){
			score+=(payment-5);
		}else{
			score+=1.5*payment-30;
		}
		return score;
	}
	public static synchronized void sendScore(int uid,int count,String note,int reason){
		
		if(new ModelService().isSendScore(uid)>0) {
			System.out.println("Send scores...");
			return ;
		}
		Score score=new Score();
		score.setNote(note);
		score.setReason(reason);
		score.setUid(uid);
		score.setOno(null);
		score.setScore(count);
		new ModelService().insertScore(new Score[]{score});
		Message message=new Message();
		message.setReceiverId(uid);
		message.setSenderId(1);
		message.setContent("您已经获得本站送出的积分"+count+" 分，每天登陆都可获得积分，积分可以用于支付餐费,详细规则请参看积分计划板块。欢迎再次访问本网站");
		message.setStatus((byte)0);
		message.save();
	}
	

}
